﻿using System.Linq;
using NUnit.Framework;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Data;

namespace Omu.AwesomeDemo.Tests
{
    [TestFixture]
    public class RepoTests 
    {
        readonly Repo<Person> repo = new Repo<Person>();

        [Test]
        public void UpdateTest()
        {
            var id = repo.Insert(new Person {FirstName = "Athene"});
            var p = repo.Get(id);
            p.FirstName = "Chiren";
            repo.Update(p);
            Assert.AreEqual(p.FirstName, repo.Get(id).FirstName);
        }

        [Test]
        public void DeleteTest()
        {
            var id = repo.Insert(new Person());
            repo.Delete(id);
            Assert.IsNull(repo.Get(id));
        }

        [Test]
        public void InsertTest()
        {
            var id = repo.Insert(new Person { FirstName = "Athene", LastName = "lol" });
            var o = repo.Get(id);
            Assert.AreEqual("Athene", o.FirstName);
        }

        [Test]
        public void GetTest()
        {
            var p = repo.Get(3);
            Assert.AreEqual(3, p.Id);
        }

        [Test]
        public void GetAllTest()
        {
            Assert.IsTrue(repo.GetAll().Count() > 10);
        }

        [Test]
        public void GetPageTest()
        {
            var page = repo.GetPage(1, 10);
            Assert.AreEqual(10, page.Count());
        }

        [Test]
        public void GetPageableTest()
        {
            var pageable = repo.GetPageable(2, 10);
            Assert.AreEqual(2, pageable.PageIndex);
            Assert.AreEqual(repo.GetPage(2, 10).Count(), pageable.Page.Count());
        }
    }
}
